package com.tvunetworks.center.device.model;

import com.tvunetworks.center.device.model.vo.TimeLockMsgResult;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Table;

/**
 * @program: tvucc-aggregator
 * @description: TimeLockMsg
 * @author lebronchen
 * @create: 2019-03-26 10:25
 **/
@Table(name = "tvu_time_lock_msg")
@Data
@Accessors(chain = true)
public class TimeLockMsg extends BaseBean {

    private String operationUserId;
    private String eventId;
    private String peerId;
    private Integer mainServer; // 1:main server 0:not main server
    private String message;
    private Integer status; // 0:excuting 1:success -1:failed null:sending
    private String msgType;// 0:send msg 1:receiver msg
    private String intranetIp;
    /**
     * 当为pack时记录正在live的rid,当移除设备R时同时移除该Pack的设备
     */
    private String liveRid;
    /**
     * R的TimeLock是否正常关闭,1表示发送消息成功,0是默认值,2表示定时任务关闭
     */

    private String receiverStatus;

    /**
     *
     * @return TimeLockMsgResult
     */
    public TimeLockMsgResult convert2TimeLockMsgResult(){
        TimeLockMsgResult result = new TimeLockMsgResult();
        result.setPeerId(peerId);
        String resultStatus = null;
        if ( this.status == null ) {
            resultStatus = "sending";
        } else {
            switch (this.status) {
                case 0:
                    resultStatus = "excuting";
                    break;
                case 1:
                    resultStatus = "success";
                    break;
                case -1:
                    resultStatus = "failed";
                    break;
                default:
                    resultStatus = "null record";
                    break;
            }
        }
        result.setStatus(resultStatus);
        return result;
    }
}
